<?php
class handle_validate
{	
	
	public function validate_email($email)
	{
		$email =  strtolower($email);
		if (preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $email)) 
		{
		  return $email;
		}
	 
		return false;
	}
	
	public function validate_postal_code($postal)
	{
		$regex = "/^([a-ceghj-npr-tv-z]){1}[0-9]{1}[a-ceghj-npr-tv-z]{1}[0-9]{1}[a-ceghj-npr-tv-z]{1}[0-9]{1}$/i";
		$postal = str_replace(' ', '', $postal);
	 
		if ( preg_match( $regex , $postal ) ) {
		  return $postal;
		} else {
		  return false;
		}
	}
	function validate_alpha_numeric($val)
    {
        return (bool)preg_match("/^([a-zA-Z0-9])+$/i", $val);
 
    }
	function validate_alpha_dash($val)
    {
        return (bool)preg_match("/^([A-Za-z_-])+$/i", $val);
 
    }
	function validate_alpha($val)
    {
        return (bool)preg_match("/^([a-zA-Z])+$/i", $val);
 
    }
	function validate_range_length($val, $min = '', $max = '')
    {
        return (strlen($val) >= $min and strlen($val) <= $max);
    }
	function validate_range_value($number,$min,$max)
    {
        return ($number > $min and $number < $max);
 
    }
	function validate_url($val)
    {
        return (bool)preg_match("^((((https?|ftps?|gopher|telnet|nntp):\/\/)|(mailto:|news:))(%[0-9A-Fa-f]{2}|[-()_.!~*';\/?:@&=+$,A-Za-z0-9])+)([).!';\/?:,][[:blank:]])?$",
            $val);
 
    }
   
 }
 
?>